// pages/business/newBusiness/newBusiness.js
import {request,Modal} from "../../../../utils/util"
import {IMG_PATH,apiList,ApiRootUrl} from "../../../../config/index"
import Toast from '../../../../@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    workList: [{
      id: new Date().getTime(),
      name: '',
      starttime: '请选择',
      endtime: '请选择',
      qualifications: '请选择',
      special: '',
      reason: '',
    }],
    baseinfo:{},
    active:0,
    orgCode:'',
    processCode:'',
    feedback:"",
    dataInfo:{},
    imgList:[],
    videoList:[],
    video_lA:'',
    img_lA:[],
    tabList:[{
      value:'基本信息',
    },{
      value:'安防系统信息'
    },{
      value:'重点要害部位'
    }],
    shifouList:[
      {
        text:'否',
        value:0
      },
      {
        text:'是',
        value:1
      }
    ],
    dictionariesList:[],
    showDictionaries:false,
    companyTypeText:'',
    companyType:'',
    manageLevelText:'',
    manageLevel:'',
    showmanageLevel:false,
    manageLevelList:[
      {value:1,text:'社区管单位'},
      {value:2,text:'所管单位'},
      {value:3,text:'分局管单位'},
      {value:4,text:'市局管单位'},
      {value:5,text:'省管单位'},
    ],
    companyName:'',
    companyAddr:'',
    fireLevel:'',
    fireLevelText:'',
    showfireLevel:false,
    fireLevelList:[
      {value:1,text:'一级'},
      {value:2,text:'二级'},
      {value:3,text:'三级'},
      {value:4,text:'一般'},
      {value:9,text:'其他'},
    ],
    girdCode:'',
    girdCodeText:'',
    showgirdCode:false,
    girdCodelList:[],
    registerTimeShow: false,
    registerTime:'',
    currentDate: new Date().getTime(),
    minDate: new Date(1920, 1, 1).getTime(),
    maxDate: new Date(2050, 1, 1).getTime(),
    maxDate1: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}`;
      } else if (type === 'month') {
        return `${value}`;
      }
      return value;
    },
    enterpriseStatus:'',
    enterpriseStatusText:'',
    showenterpriseStatus:false,
    enterpriseStatusList:[
      {value:'0',text:'正常'},
      {value:'1',text:'注销'}
    ],
    isSpecial:'',
    isSpecialText:'',
    showisSpecial:false,
    specialType:'',
    specialTypeText:'',
    showspecialType:false,
    specialTypeList:[], 
    registerFunds:'',
    registerAddr:'',
    companyPhone:'',
    companyPhone:'',
    companyFax:'',
    specialNumber:'',
    isMajor:'',
    isMajorText:'',
    showisMajor:false,
    majorType:'',
    majorTypeText:'',
    showmajorType:false,
    majorTypeList:[{
      value:'1',
      text:'反恐重点单位'
    },{
      value:'2',
      text:'反恐要素单位'
    }], 
    majorLevel:'',
    majorLevelText:'',
    showmajorLevel:false,
    majorLevelList:[{
      value:'1',
      text:'一级'
    },{
      value:'2',
      text:'二级'
    },{
      value:'3',
      text:'三级'
    }], 
    internalStandard:'',
    internalStandardText:'',
    showinternalStandard:false,
    internalStandardList:[{
      value:'0',
      text:'是'
    },{
      value:'1',
      text:'否'
    }], 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self=this
    console.log(options);
    self.setData({
      orgCode:options.orgCode,
      processCode:options.processCode
    })
    // self.getDetail()
  },

  // 下一步及提交
  update(){
    let self=this
    if(self.data.active==0){
      self.setData({
        active:1
      })
      return
    }
    if(self.data.active==1){
      self.setData({
        active:2
      })
    }
    if(self.data.active==2){

    }
  },
   //切换首页标签
   onChange(value){
    let self=this
    this.setData({
      active:value.detail.index
    })
   
  },
  getDetail(e) {
    let self = this;

      let params = {
        processCode: self.data.processCode,
        orgCode: self.data.orgCode
      }
      Toast.loading({
        message: '加载中...',
        mask: true,
        duration: 0,
        forbidClick: true,
      });
      wx.request({
        url: `${ApiRootUrl}/cloudCheckTask/queryCloudTaskDetail`,
        method: 'GET',
        header: {
          'content-type': 'application/json; charset=utf-8',
          'cookie': wx.getStorageSync("sessionid")
        },
        params: params,
        data: params,
        success(res) {
          Toast.clear();
          if (res.data.code == 20000) {
            console.log(res);
          }else {
            Toast({
              duration: 3000,
              forbidClick: true,
              type: 'fail',
              message: res.data.message,
              mask:true
            });
          }
        },
        fail(res) {
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: '网络已断开',
          });
        }
      })
 
  },
  //单位类别
  dictionariesListCancel() {
    this.setData({
      showDictionaries: false
    })
  },
  dictionariesListConfirm(event) {
    console.log(event);
    this.setData({
      companyType: event.detail.value.value,
      companyTypeText: event.detail.value.text,
      showDictionaries:false
    })
  },
  getDictionariesList(e) {
    let self = this;
      let params = {
        dictionaryType: 'UnitCategory',
      }
      Toast.loading({
        message: '加载中...',
        mask: true,
        duration: 0,
        forbidClick: true,
      });
      wx.request({
        url: `${ApiRootUrl}/dictionaries/querytbDictionariesList`,
        method: 'GET',
        header: {
          'content-type': 'application/json; charset=utf-8',
          'cookie': wx.getStorageSync("sessionid")
        },
        params: params,
        data: params,
        success(res) {
          Toast.clear();
          if (res.data.code == 20000) {
            console.log(res);
            let dictionariesList=[]
            res.data.data.forEach(item=>{
              let obj={text:item.dictionaryName,
              value:item.dictionaryCode
              }
              dictionariesList.push(obj)
            })
            self.setData({
              dictionariesList:dictionariesList,
              showDictionaries:true
            })
          }else {
            Toast({
              duration: 3000,
              forbidClick: true,
              type: 'fail',
              message: res.data.message,
              mask:true
            });
          }
        },
        fail(res) {
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: '网络已断开',
          });
        }
      })
  },
  //管理级别
  manageLevelCancel() {
    this.setData({
      showmanageLevel: false
    })
  },
  manageLevelConfirm(event) {
    console.log(event);
    this.setData({
      manageLevel: event.detail.value.value,
      manageLevelText: event.detail.value.text,
      showmanageLevel:false
    })
  },
  getmanageLevel(e) {
    this.setData({
      showmanageLevel:true
    })
  },
  //消防等级
  fireLevelCancel() {
    this.setData({
      showfireLevel: false
    })
  },
  fireLevelConfirm(event) {
    console.log(event);
    this.setData({
      fireLevel: event.detail.value.value,
      fireLevelText: event.detail.value.text,
      showfireLevel:false
    })
  },
  getfireLevel(e) {
    this.setData({
      showfireLevel:true
    })
  },
  //所属责任区
  girdCodeCancel() {
    this.setData({
      showgirdCode: false
    })
  },
  girdCodeConfirm(event) {
    console.log(event);
    this.setData({
      fireLevel: event.detail.value.value,
      fireLevelText: event.detail.value.text,
      showfireLevel:false
    })
  },
  getgirdCode(e) {
    let self = this;
    let params = {
    }
    Toast.loading({
      message: '加载中...',
      mask: true,
      duration: 0,
      forbidClick: true,
    });
    wx.request({
      url: `${ApiRootUrl}/cloudCheckTask/queryAllGirds`,
      method: 'GET',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      params: params,
      data: params,
      success(res) {
        Toast.clear();
        if (res.data.code == 20000) {
          console.log(res);
          let girdCodelList=[]
          res.data.data.forEach(item=>{
            let obj={text:item.gridName,
            value:item.id
            }
            girdCodelList.push(obj)
          })
          self.setData({
            girdCodelList:girdCodelList,
            showgirdCode:true
          })
        }else {
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
            mask:true
          });
        }
      },
      fail(res) {
        Toast.clear();
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
  },
  //注册日期
  getregisterTime(event) {
    this.setData({
      registerTimeShow: true,
    })
  },
  registerTimeCancel() {
    this.setData({
      registerTimeShow: false,
    })
  },
  registerTimeConfirm(event) {
    let time = this.formatDate(event.detail);

    this.setData({
      registerTime: time,
      registerTimeShow: false
    })
  },
  formatDate(date) {
    var date = new Date(date);
    var YY = String(date.getFullYear()) ;
    var MM = String((date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)) ;
    var DD = String((date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())) ;
    return YY + MM + DD;
  },
  //机构状态
  enterpriseStatusCancel() {
    this.setData({
      showenterpriseStatus: false
    })
  },
  enterpriseStatusConfirm(event) {
    console.log(event);
    this.setData({
      enterpriseStatus: event.detail.value.value,
      enterpriseStatusText: event.detail.value.text,
      showenterpriseStatus:false
    })
  },
  getenterpriseStatus(e) {
    this.setData({
      showenterpriseStatus:true
    })
  },
  //是否是特种行业
  isSpecialCancel() {
    this.setData({
      showisSpecial: false
    })
  },
  isSpecialConfirm(event) {
    console.log(event);
    this.setData({
      isSpecial: event.detail.value.value,
      isSpecialText: event.detail.value.text,
      showisSpecial:false
    })
  },
  getisSpecial(e) {
    this.setData({
      showisSpecial:true
    })
  },
  //特种行业类别
  specialTypeCancel() {
    this.setData({
      showspecialType: false
    })
  },
  specialTypeConfirm(event) {
    console.log(event);
    this.setData({
      specialType: event.detail.value.value,
      specialTypeText: event.detail.value.text,
      showspecialType:false
    })
  },
  getspecialType(e) {
    let self = this;
      let params = {
        dictionaryType: 'SpecialLineCategory',
      }
      Toast.loading({
        message: '加载中...',
        mask: true,
        duration: 0,
        forbidClick: true,
      });
      wx.request({
        url: `${ApiRootUrl}/dictionaries/querytbDictionariesList`,
        method: 'GET',
        header: {
          'content-type': 'application/json; charset=utf-8',
          'cookie': wx.getStorageSync("sessionid")
        },
        params: params,
        data: params,
        success(res) {
          Toast.clear();
          if (res.data.code == 20000) {
            console.log(res);
            let specialTypeList=[]
            res.data.data.forEach(item=>{
              let obj={text:item.dictionaryName,
              value:item.dictionaryCode
              }
              specialTypeList.push(obj)
            })
            self.setData({
              specialTypeList:specialTypeList,
              showspecialType:true
            })
          }else {
            Toast({
              duration: 3000,
              forbidClick: true,
              type: 'fail',
              message: res.data.message,
              mask:true
            });
          }
        },
        fail(res) {
          Toast.clear();
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: '网络已断开',
          });
        }
      })
  },
  //是否是反恐重点单位
  isMajorCancel() {
    this.setData({
      showisMajor: false
    })
  },
  isMajorConfirm(event) {
    console.log(event);
    this.setData({
      isMajor: event.detail.value.value,
      isMajorText: event.detail.value.text,
      showisMajor:false
    })
  },
  getisMajor(e) {
    this.setData({
      showisMajor:true
    })
  },
  //反恐重点单位类型
  majorTypeCancel() {
    this.setData({
      showmajorType: false
    })
  },
  majorTypeConfirm(event) {
    console.log(event);
    this.setData({
      majorType: event.detail.value.value,
      majorTypeText: event.detail.value.text,
      showmajorType:false
    })
  },
  getmajorType(e) {
    this.setData({
      showmajorType:true
    })
  },
  //反恐单位等级
  majorLevelCancel() {
    this.setData({
      showmajorLevel: false
    })
  },
  majorLevelConfirm(event) {
    console.log(event);
    this.setData({
      majorLevel: event.detail.value.value,
      majorLevelText: event.detail.value.text,
      showmajorLevel:false
    })
  },
  getmajorLevel(e) {
    this.setData({
      showmajorLevel:true
    })
  },
  //是否符合国标
  internalStandardCancel() {
    this.setData({
      showinternalStandard: false
    })
  },
  internalStandardConfirm(event) {
    console.log(event);
    this.setData({
      internalStandard: event.detail.value.value,
      internalStandardText: event.detail.value.text,
      showinternalStandard:false
    })
  },
  getinternalStandard(e) {
    this.setData({
      showinternalStandard:true
    })
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})